home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / Wood.0.72 / Sources / AuxFiles / objctree < prev    next >
Encoding:
Text File  |  1995-09-21  |  2.0 KB  |  105 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # Usage: objctree [options] [files]
  4.  
  5. # Configuration parameters
  6.  
  7. require "pwd.pl";
  8.  
  9. &initpwd;
  10.  
  11. $CPP = 'cc -E';
  12.  
  13. # Process switches
  14.  
  15. while ($ARGV[0] =~ /^-/) {
  16.     $_ = shift;
  17.     if (/^-D(.*)/) {
  18.         $defines .= "-D" . ($1 ? $1 : shift);
  19.     }
  20.     elsif (/^-I(.*)/) {
  21.         $includes .= "-I" . ($1 ? $1 : shift);
  22.     }
  23.     elsif (/^-o(.*)/) {
  24.         $outfile = ($1 ? $1 : shift);
  25.     }
  26.     elsif (/^-r(.*)/) {
  27.         $rootclass = ($1 ? $1 : shift);
  28.     }
  29.     else {
  30.         shift;
  31.     }
  32. }
  33.  
  34. if (-e "./sym" && -d "./sym") {
  35.     open(ALLHEADERS ,">./sym/classtree.h") || die "Can't open ./sym/classtree.h: $!\n";
  36.     $allheadersfile = "./sym/classtree.h";
  37.     foreach $file (@ARGV) {
  38.         print ALLHEADERS "#import \"../".$file."\"\n";
  39.     }
  40.     $cppcommand = "$CPP -O -g -Wall -ObjC $defines $includes $allheadersfile|";
  41. else {
  42.     system("mkdir /tmp/".$ENV{USER});
  43.     open(ALLHEADERS ,">/tmp/$ENV{USER}/classtree.h") || die "Can't open /tmp/$ENV{USER}/classtree.h: $!\n";
  44.     $allheadersfile = "/tmp/".$ENV{USER}."/classtree.h";
  45.     foreach $file (@ARGV) {
  46.         print ALLHEADERS "#import \"".$file."\"\n";
  47.     }
  48.     $cppcommand = "$CPP -O -g -Wall -ObjC $defines $includes -I$ENV{PWD} $allheadersfile|";
  49. }
  50. close ALLHEADERS;
  51.  
  52. open(CPP,$cppcommand) || die "Can't run cpp: $!\n";
  53.     
  54. while (<CPP>) {
  55.     next unless /^\@interface/;
  56.     ($junk,$child,$parent,$trash) = split(/[ \t\n:]+/,$_,4);
  57.     if ($parent) {
  58.         if (! $hierarchy{$parent} || ! ($hierarchy{$parent} =~ /$child/)) {
  59.                 $hierarchy{$parent} .= $child . ",";
  60.         }
  61.     }
  62. }
  63. close CPP;
  64.  
  65. if ($outfile) {
  66.     open(RESULT, ">$outfile") || die "Can't open classtree: $!\n";
  67. } else {
  68.     open(RESULT, ">classtree") || die "Can't open classtree: $!\n";
  69. }
  70.  
  71.  
  72. if ($rootclass) {
  73.     &printTree($rootclass);
  74. } else {
  75.     &printTree("Object");
  76. }
  77.  
  78. print RESULT "\n";
  79.  
  80. close RESULT;
  81.  
  82. sub printTree {
  83.     local($name) = @_;
  84.     local($child);
  85.     local(@children);
  86.     
  87.     if ($hierarchy{$name}) {
  88.         @children = split(/,/,$hierarchy{$name});
  89.         print RESULT "{", $name;
  90.         foreach $child (@children) {
  91.             print RESULT ", ";
  92.             &printTree($child);
  93.         }
  94.         print RESULT "}";
  95.     }
  96.     else {
  97.         print RESULT $name;
  98.     }
  99. }
  100.     
  101.     
  102.     
  103.  
  104.